package com.evil.enterprise.controller;

import com.evil.account.api.RemoteUserEnterpriseService;
import com.evil.account.pojo.dto.enterprise.EnterpriseBaseInfoResp;
import com.evil.common.account.dto.user.EnableUsersReqDTO;
import com.evil.common.account.dto.user.enterprise.EnterpriseUsersReqDTO;
import com.evil.common.account.dto.user.enterprise.MineEnterprisesReqDTO;
import com.evil.common.account.enums.PlatformTypeEnum;
import com.evil.common.core.entity.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户企业接口
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@RestController
@RequestMapping("/user/enterprise")
@AllArgsConstructor
public class UserEnterpriseController {

    private final RemoteUserEnterpriseService remoteUserEnterpriseService;

    /**
     * 当前用户 企业列表
     *
     * @return R
     */
    @PostMapping("/mine-enterprises")
    public R<List<EnterpriseBaseInfoResp>> mineEnterprises() {
        return R.success(remoteUserEnterpriseService.mineEnterprises(new MineEnterprisesReqDTO(PlatformTypeEnum.ENTERPRISE.getId())));
    }

    /**
     * 禁用用户
     *
     * @param enableUsersReqDTO enableUsersReqDTO
     * @return R
     */
    @PostMapping("/disable")
    public R<?> enable(@Validated @RequestBody EnableUsersReqDTO enableUsersReqDTO) {
        enableUsersReqDTO.setEnterpriseId(null);
        remoteUserEnterpriseService.enable(enableUsersReqDTO);
        return R.success();
    }

    /**
     * 删除用户企业
     *
     * @param enterpriseUsersReqDTO enterpriseUsersReqDTO
     * @return R
     */
    @PostMapping("/batch-delete")
    public R<?> deleteUserEnterpriseBatch(@Validated @RequestBody EnterpriseUsersReqDTO enterpriseUsersReqDTO) {
        enterpriseUsersReqDTO.setEnterpriseId(null);
        remoteUserEnterpriseService.deleteUserEnterpriseBatch(enterpriseUsersReqDTO);
        return R.success();
    }
}
